package pers.qianyu.month_202011.date_20201117;

/**
 * 198. 打家劫舍
 * https://leetcode-cn.com/problems/house-robber/submissions/
 *
 * @author mizzle rain
 * @date 2020-11-17 21:55
 */
public class RobOne {
    /**
     * 优化动态规划的空间
     */
    public int rob(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int a = 0, b = nums[0];
        for (int i = 1; i < nums.length; i++) {
            int temp = Math.max(b, a + nums[i]);
            a = b;
            b = temp;
        }
        return b;
    }
}
